<?php
include ('db.php');
session_start();
$sql="SELECT *FROM msg ORDER by id DESC";
$my_result=$mysql->query($sql);
$big=array();
while ($row=$my_result->fetch_array(MYSQLI_ASSOC)){
    $big[]=$row;
}
//while (true){
//    $row=$my_result->fetch_array(MYSQLI_ASSOC);
//    if($row==false){
//        break;
//    }
//    var_dump($row);
//}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>留言板</title>
    <link href="2.css" rel="stylesheet" />
</head>
<body>
<div class="add">
    <form action="http://127.0.0.1:8080/php/ziji/4/index.php" method="post">

        <textarea name="contact" class="area"></textarea>

        <input name="user" class="text" type="text">

        <input class="btn" type="submit" value="发布">
        <a style="float: right" href="login.php">登记</a>
    </form>
    <div class="msg">
        <?php
            foreach ($big as $row) {
                $t=date('y-m-d H:s:i',$row['time']);
        ?>
                <div class="item">
                    <span class="about 19"><?php echo $row['username']?></span>
                    <span class="time"><?php echo $t?>
                        <?php
                        if(isset($_SESSION['user'])!==false) {
                            ?>
                            <a onclick="return confirm('你要确定删除吗？')" href="delete.php?id=<?php echo $row['id'] ?>">删除</a>
                            <?php
                        }
                        ?>
                   </span>
                    <p> <?php echo $row['contact']?></p>
                </div>
        <?php
        }
        ?>
    </div>
</div>
</body>
</html>